#include <iostream>
#include "contacts.pb.h"

int main()
{
    std::string people_string;

    {
        contacts::PeopleInfo people;
        people.set_name("张三");
        people.set_age(18);
        //序列化
        if(!people.SerializeToString(&people_string))
        {
            std::cerr << "people序列化失败" << std::endl;
            return -1;
        }
        std::cout << "序列化成功: " << people_string << std::endl;
    }
    
    {
        contacts::PeopleInfo people;
        if(!people.ParseFromString(people_string))
        {
            std::cerr << "people反序列化失败" << std::endl;
            return -1;
        }
        std::cout << "反序列化成功: " << std::endl
                  << "姓名: " << people.name() << std::endl
                  << "年龄: " << people.age() << std::endl;
    }


}